# -*- coding: utf-8 -*-
#!/usr/bin/python
# @Date : 2021-11-12
# @Author : zhu
# @File : excelop.py
# @Software: VS
from openpyxl import load_workbook, Workbook
import os
import datetime
BASE_PATH = os.path.dirname(os.path.abspath(__file__))

class ZExcel:

    def __init__(self,path=None):
        if path:
            self.wb = load_workbook(os.path.join(BASE_PATH,path))
        else:
            self.wb = Workbook()
        self.sheet = self.wb.active
        self.cell = self.sheet.cell

    def set_value_by_cell(self,row,column,value):
        '''
        通过cell设置值
        :param row(int):列
        :param column(int):行
        :param value(str):设置值
        '''
        self.cell(row,column).value = value

    def set_value_by_table(self,tag,value):
        '''通过A1坐标设置值'''
        self.sheet[tag] = value

    def get_value_by_table(self,tag):
        '''通过A1坐标设置值'''
        return self.sheet[tag]

    def get_value_by_cell(self,row,column):
        '''通过cell坐标设置值 row行 colunm列'''
        return self.cell(row,column).value

    def save(self,filename):
        self.wb.save(filename+".xlsx")


if __name__ == '__main__':
    # title = ['序号','姓名']
    filename = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
    ex = ZExcel()
    ex.set_value_by_cell(1, 2, "0列第二行")
    ex.save(filename)

